<?php
	include '../controllers/DBController.php';
	$category = $_REQUEST['category'];
	$searchWord = $_REQUEST['searchWord'];
	$mainWord = getMainWordByContent($searchWord, $category);
	if ($mainWord == null) {
		echo("<script language=javascript>alert('没有查询到该单词！'); history.go(-1)</script>");
	}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<script src="../js/addword.js"></script>	

</head>
<body>

	<script type="text/javascript">
		wordId = <?php echo $mainWord->wordId;?>;
		meaningCount = <?php echo count($mainWord->meanings) + 1;?>;
		totalAddedMeaning = meaningCount;
		var meaningArray = new Array(100);

		<?php 
			for ($i = 1; $i <= count($mainWord->meanings); $i++) {
				$meaning = $mainWord->meanings[$i-1];
				echo "meaningArray[".$i."]=".$meaning->meaningId.";";
			}
		?>
	</script>
	
	<div id='mainDiv'>
		<a href='main.php?category=<?php echo $category ?>'>返回管理首页</a><hr/>
		<input type="hidden" id="category" value="<?php echo $category ?>"/>
		<table id='wordTable' border='2' rules='rows' cellpadding='8%' align='center' width='80%'>
			<tr><th>单词</th><td colspan='4'><input id='mainWord' type='text' size=20 value='<?php echo $mainWord->content?>'></input></td></tr>
			<tr><th>音标</th><td colspan='4'><input id='slug' type='text' size=20 value='<?php echo $mainWord->slug?>'></input></td></tr>
			<tr><th>更新词汇</th><td colspan='4'><select id='isUpdate'><option  <?php 
				if (strlen($mainWord->wordIndex) == 1) {
					echo "selected='selected'";
			}?> value='0'>否</option><option 
				<?php 
				if (strlen($mainWord->wordIndex) > 1) {
					echo "selected='selected'";
			}?>
			value='1'>是</option></select></td></tr>
			<tr><td colspan='5' align='center' height='30'>
				<div id='wordOperationArea'>
					<input type='button' value='添加含义' onclick='addMeaningHTML();'></input>
					&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='修改单词' onclick='updateWord(<?php echo $category?>);'></input>
					&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='删除单词' onclick='deleteWord();'></input>
				</div>
			</td></tr>
			<tr><td colspan='5' style='background-color:gray'></td></tr>	
			
			<?php 
				for ($i = 0; $i < count($mainWord->meanings) ;$i++)
				{
					$meaning = $mainWord->meanings[$i];
					?>
						<tr id = 'meaningArea_<?php echo $i+1?>'><td colspan='5' align='center'>
								<table width='90%' rules='all' cellpadding='5%'>
									<tr><th colspan='5' align='center' width='200'>含义<?php echo $i+1?><input type='button' value='删除该含义' onclick='deleteMeaning(<?php echo $i+1?>);'></input></th></tr>
									<tr><th colspan='1'>中文含义</th>
									<td colspan='4'><input id='meaning_chinese_<?php echo $i+1?>' type='text' size=120 value='<?php echo $meaning->cnTranslate?>'></input></td></tr>
									<tr><th colspan='1'>英文含义</th>
									<td colspan='4'><input id='meaning_english_<?php echo $i+1?>' type='text' size=120 value='<?php echo $meaning->engTranslate?>'></input></td></tr>
									<tr><td colspan='5' align='center'><input type='button' value='修改含义' onclick='updateMeaning(<?php echo $i+1?>)'></input></td></tr>									
									<tr><th colspan='1'>同义词</th><td colspan='4'>
									<table id='synonym_<?php echo $i+1?>'>
									<?php 
										for ($j = 0; $j < count($meaning->synonyms); $j++) {
											$synonym = $meaning->synonyms[$j];
											?>
												<tr id='<?php echo $synonym->synonymId ?>'><td><?php echo $synonym->content?></td><td><input type='button' value='删除' onclick='deleteSynonym(<?php echo $i+1?>,<?php echo $synonym->synonymId ?>);'/></td></tr>
											<?php 
										}
									?>
									<tr><td colspan='2'><input id='synonym_input_<?php echo $i+1?>' type='text' size='20'></input></td></tr>
									<tr><td colspan='2'><input type='button' value='添加同义词' onclick='addSynonym(<?php echo $i+1?>);'></input></td></tr>
									</table></td></tr>
									<tr><th colspan='1'>反义词</th><td colspan='4'>
									<table id='antonym_<?php echo $i+1?>'>
									<?php 
										for ($j = 0; $j < count($meaning->antonyms); $j++) {
											$antonym = $meaning->antonyms[$j];
											?>
												<tr id='<?php echo $antonym->antonymId ?>'><td><?php echo $antonym->content?></td><td><input type='button' value='删除' onclick='deleteAntonym(<?php echo $i+1?>,<?php echo $antonym->antonymId ?>);'/></td></tr>
											<?php 
										}
									?>
									<tr><td colspan='2'><input id='antonym_input_<?php echo $i+1?>' type='text' size='20'></input></td></tr>
									<tr><td colspan='2'><input type='button' value='添加反义词' onclick='addAntonym(<?php echo $i+1?>);'></input></td></tr>
									</table></td></tr>
									<tr><th colspan='1'>例句</th><td colspan='4'>
									<table id='sentence_<?php echo $i+1?>'>
									
									<?php 
										for ($j = 0; $j < count($meaning->sentences); $j++) {
											$sentence = $meaning->sentences[$j];
											?>
												<tr id='<?php echo $sentence->sentenceId ?>'><td><?php echo $sentence->content?></td><td><input type='button' value='删除' onclick='deleteSentence(<?php echo $i+1?>,<?php echo $sentence->sentenceId ?>);'/></td></tr>
											<?php 
										}
									?>
									
									<tr><td colspan='2'><input id='sentence_input_<?php echo $i+1?>' type='text' size='120'></input></td></tr>
									<tr><td colspan='2'><input type='button' value='添加例句' onclick='addSentence(<?php echo $i+1?>);'></input></td></tr>
									</table></td></tr>
									</table></td></tr>
					<?php 
				}
			?>
				
		</table>
	</div>
	
</body>
</html>
